package com.stox.ui.javafx.charting.event.handler;

import javafx.event.EventHandler;
import javafx.scene.input.ScrollEvent;

import org.controlsfx.control.RangeSlider;
import org.springframework.stereotype.Component;

import com.stox.ui.javafx.charting.view.ChartingView;

@Component
public class ZoomEventHandler implements EventHandler<ScrollEvent> {

	@Override
	public void handle(ScrollEvent event) {
		if(event.getSource() instanceof ChartingView) {
			ChartingView chartingView = (ChartingView)event.getSource();
			RangeSlider rangeSlider = chartingView.getPrimaryChart().getRangeSlider();
			
			double multiple = event.getDeltaY()/chartingView.getHeight(); 
			double lowValue = rangeSlider.getLowValue();
			double highValue = rangeSlider.getHighValue();
			
			rangeSlider.setLowValue(lowValue - lowValue*multiple);
			rangeSlider.setHighValue(highValue + highValue*multiple);
    	  }
	}

}
